#ifndef PARSERSTREAM_H
#define PARSERSTREAM_H
#include <string>
using namespace std;

template<typename T = char>
class GenericParseStream {
	public:
		//Constructors
		GenericParseStream() {}
		GenericParseStream(T* _stream) : i(0) {
			int j;
			for (j = 0; _stream[j] != 0; ++j) ;
			length = j+1;
			stream = new T[j+1];
			for (j = 0; j < length; ++j) stream[j] = _stream[j];
		}
		GenericParseStream(T const* _stream) : i(0) {
			unsigned int j;
			for (j = 0; _stream[j] != 0; ++j) ;
			length = j+1;
			stream = new T[j+1];
			for (j = 0; j < length; ++j) stream[j] = _stream[j];
		}
		
		inline T get() { return stream[i]; }
		inline void next() { ++i; }
		inline void previous() { --i; }
		inline bool endstream() { return i > length; }
		inline unsigned int getPosition() { return i; }
		inline void setPosition(unsigned int to_set) { i = to_set; }
		inline T* get(unsigned int i, unsigned int j) {
			T* substream = new T[j-i];
			for (unsigned int k = 0; k < j-i; ++k) substream[k] = stream[k+i];
			substream[j-i] = 0;
			return substream;
		}
		
		typedef T* iterator;
		
		inline T* begin() { return &stream[0]; }
		inline T* end() { return &stream[length]; }
	private:
		T* stream;
		unsigned int i;
		unsigned int length;
};

typedef GenericParseStream<> ParseStream;

#endif
